#include "widget.h"
#include "ui_widget.h"
#include <QMessageBox>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
    , m_ptcpsocket(new QTcpSocket)
{
    ui->setupUi(this);

    init_network();


}

Widget::~Widget()
{
    delete ui;
}

void Widget::connect_ok()
{
    QMessageBox::information(this, "client connect", "connect server success");
    return;
}

void Widget::init_network(){
    m_ptcpsocket->connectToHost("127.0.0.1", 8099);

    connect(m_ptcpsocket, &QTcpSocket::readyRead, this, &Widget::ready_read);

    return;
}

void Widget::ready_read(){
    QByteArray ba = m_ptcpsocket->readAll();

    QString strdata = QString::fromUtf8(ba);

    QMessageBox::information(this, "client", "get message");

    ui->label->setText(strdata);
}


